package com.itggm.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itggm.DTO.MessagePageDTO;
import com.itggm.mapper.MessageMapper;
import com.itggm.pojo.Message;
import com.itggm.response.ResponseResult;
import com.itggm.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: ggm
 * @data 2024年11月19日 10:33
 * 留言管理
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageMapper messageMapper;

    @Override
    public ResponseResult page(MessagePageDTO messagePageDTO) {
        PageHelper.startPage(messagePageDTO.getPage(),messagePageDTO.getLimit());
        List<Message> messages =messageMapper.page(messagePageDTO);
        PageInfo<Message> pageInfo = new PageInfo<>(messages);
        List<Message> list = pageInfo.getList();
        long total = pageInfo.getTotal();
        return ResponseResult.success().count(total).data(list);
    }
    @Transactional
    @Override
    public ResponseResult delete(List<Integer> listIds) {
         messageMapper.deleteMessage(listIds);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult editMessage(Integer id) {

        messageMapper.updateMessage(id);

        return ResponseResult.success();
    }

    @Override
    public ResponseResult publishMessage(Message message) {

        messageMapper.insertMessage(message);

        return ResponseResult.success();
    }
}
